﻿using System;
using System.Collections.ObjectModel;
using System.Data;
using System.IO;

using PublicDomain.Data.Csv;
using PublicDomain.Data.Csv.Metadata;

namespace PublicDomain.UnitTest.Data.Csv
{
    public static class TestDataFactory
    {
        public static CsvDataReader GetTestFileCsvDataReader(string csvFilePath)
        {
            var csvDataFormat = GetTestFileCsvDataFormat(csvFilePath);
            var result = new CsvDataReader(csvFilePath, csvDataFormat);

            return result;
        }

        public static CsvDataFormat GetTestFileCsvDataFormat(string csvFilePath)
        {
            if ("GetValueTestCsvFile.csv".Equals(csvFilePath, StringComparison.OrdinalIgnoreCase))
            {
                var result = new CsvDataFormat
                {
                    Name = Path.GetFileNameWithoutExtension(csvFilePath),
                    CsvColumnsDefinitions = new Collection<CsvColumnDefinition> 
                    { 
                        new CsvColumnDefinition { ColumnOrdinal = 00, ColumnName = "Column00", DataType = DbType.AnsiString, Tag = "ABC" },
                        new CsvColumnDefinition { ColumnOrdinal = 01, ColumnName = "Column01", DataType = DbType.AnsiStringFixedLength, Tag = "USA" },
                        new CsvColumnDefinition { ColumnOrdinal = 02, ColumnName = "Column02", DataType = DbType.Binary, Tag = "266E813D5816" },
                        new CsvColumnDefinition { ColumnOrdinal = 03, ColumnName = "Column03", DataType = DbType.Boolean, Tag = false },
                        new CsvColumnDefinition { ColumnOrdinal = 04, ColumnName = "Column04", DataType = DbType.Byte, Tag = (byte)128 },
                        new CsvColumnDefinition { ColumnOrdinal = 05, ColumnName = "Column05", DataType = DbType.Currency, Tag = 567.34m },
                        new CsvColumnDefinition { ColumnOrdinal = 06, ColumnName = "Column06", DataType = DbType.Date, Tag = new DateTime(2013, 08, 11) },
                        new CsvColumnDefinition { ColumnOrdinal = 07, ColumnName = "Column07", DataType = DbType.DateTime, Tag = new DateTime(1917, 08, 27) },
                        new CsvColumnDefinition { ColumnOrdinal = 08, ColumnName = "Column08", DataType = DbType.DateTime2, Tag = new DateTime(1941, 06, 22) },
                        new CsvColumnDefinition { ColumnOrdinal = 09, ColumnName = "Column09", DataType = DbType.DateTimeOffset, Tag = new DateTimeOffset(new DateTime(1956, 03, 12), new TimeSpan(11, 00, 00)) },
                        new CsvColumnDefinition { ColumnOrdinal = 10, ColumnName = "Column10", DataType = DbType.Decimal, Tag = 12331.902m },
                        new CsvColumnDefinition { ColumnOrdinal = 11, ColumnName = "Column11", DataType = DbType.Double, Tag = 785.12D },
                        new CsvColumnDefinition { ColumnOrdinal = 12, ColumnName = "Column12", DataType = DbType.Guid, Tag = new Guid("916BB212-7771-4B80-9F24-266E813D5816") },
                        new CsvColumnDefinition { ColumnOrdinal = 13, ColumnName = "Column13", DataType = DbType.Int16, Tag = (short)12846 },
                        new CsvColumnDefinition { ColumnOrdinal = 14, ColumnName = "Column14", DataType = DbType.Int32, Tag = (int)32412351 },
                        new CsvColumnDefinition { ColumnOrdinal = 15, ColumnName = "Column15", DataType = DbType.Int64, Tag = (long)324123511233 },
                        new CsvColumnDefinition { ColumnOrdinal = 16, ColumnName = "Column16", DataType = DbType.Object, Tag = "916BB212" },
                        new CsvColumnDefinition { ColumnOrdinal = 17, ColumnName = "Column17", DataType = DbType.SByte, Tag = (sbyte)-128 },
                        new CsvColumnDefinition { ColumnOrdinal = 18, ColumnName = "Column18", DataType = DbType.Single, Tag = (Single)934.45 },
                        new CsvColumnDefinition { ColumnOrdinal = 19, ColumnName = "Column19", DataType = DbType.String, Tag = "text234" },
                        new CsvColumnDefinition { ColumnOrdinal = 20, ColumnName = "Column20", DataType = DbType.StringFixedLength, Tag = "text19" },
                        new CsvColumnDefinition { ColumnOrdinal = 21, ColumnName = "Column21", DataType = DbType.Time, Tag = new TimeSpan(22, 36, 00) },
                        new CsvColumnDefinition { ColumnOrdinal = 22, ColumnName = "Column22", DataType = DbType.UInt16, Tag = (UInt16)65535 },
                        new CsvColumnDefinition { ColumnOrdinal = 23, ColumnName = "Column23", DataType = DbType.UInt32, Tag = (UInt32)4294967295 },
                        new CsvColumnDefinition { ColumnOrdinal = 24, ColumnName = "Column24", DataType = DbType.UInt64, Tag = (UInt64)18446744073709551615 },
                        new CsvColumnDefinition { ColumnOrdinal = 25, ColumnName = "Column25", DataType = DbType.VarNumeric, Tag = 1123332.41235m },
                        new CsvColumnDefinition { ColumnOrdinal = 26, ColumnName = "Column26", DataType = DbType.Xml, Tag = "<Root></Root>" }
                    }
                };

                return result;
            }

            return null;
        }
    }
}
